package com.ruoyi.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.domain.dao.BookMark;
import com.ruoyi.service.BookMarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @auther: zxw
 * @Description //视角标签模块
 * @date: 2025/7/7 下午1:35
 */

@Api(tags = "业务——书签管理")
@RestController
@RequestMapping("/admin/bookmark")
@Validated
public class BookMarkController {

    @Autowired
    private BookMarkService bookMarkService;

    @ApiOperation("获取书签信息")
    @GetMapping("/info")
    public ResponseEntity<Object> getBookMarkInfo() {
        List list = bookMarkService.getBookMarkInfo();
        return ResponseEntity.ok(list);
    }


    @ApiOperation("添加书签信息")
    @PostMapping("/add")
    public ResponseEntity<Object> addBookMarkInfo(@RequestParam(value = "file") MultipartFile file,
                                                  @RequestParam("name") String name,
                                                  @RequestParam("lon") String lon,
                                                  @RequestParam("lat") String lat,
                                                  @RequestParam("height") String height,
                                                  @RequestParam("pitch") String pitch,
                                                  @RequestParam("heading") String heading,
                                                  @RequestParam("roll") String roll) {

        Map map = new HashMap();
        try {
            BookMark bookMark = new BookMark();
            bookMark.setName(name);
            bookMark.setLon(lon);
            bookMark.setLat(lat);
            bookMark.setHeight(height);
            bookMark.setPitch(pitch);
            bookMark.setHeading(heading);
            bookMark.setRoll(roll);
            bookMarkService.addBookMarkInfo(file, bookMark);
            map.put("isSuccess", true);
            return ResponseEntity.ok(map);
        } catch (Exception e) {
            map.put("isSuccess", false);
            return ResponseEntity.ok(map);
        }

    }


    @ApiOperation("删除书签信息")
    @GetMapping("/delete/{id}")
    public ResponseEntity<Object> deleteBookMarkInfo(@PathVariable("id") Integer id) {
        Map map = new HashMap();
        try {
            bookMarkService.delBookMark(id);
            map.put("isSuccess", true);
            return ResponseEntity.ok(map);
        } catch (Exception e) {
            map.put("isSuccess", false);
            return ResponseEntity.ok(map);
        }
    }

    @ApiOperation("按照名称模糊查询书签信息")
    @GetMapping("/getInfoByName")
    public ResponseEntity<Object> getInfoByName(@RequestParam("name") String name) {
        List<BookMark> list = bookMarkService.getInfoByName(name);
        return ResponseEntity.ok(list);
    }








}
